/* ladd.t   ALLOCATION DETAIL BY LOCATION DELETE TRIGGER              */
/*Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                 */
/*All rights reserved worldwide.  This is an unpublished work.        */
/*V8:ConvertMode=NoConvert*/
/*********************************************************************/
/*  Program :ladd.t                                                  */
/*  Author  :Ben Holmes                                              */
/*  Date    :03/19/95                                                */
/*  !Description : lad_det DELETE trigger program                    */
/*          : In order to enhance this trigger to support additional */
/*          : interfaces, add a DO-END block similar to the one      */
/*          : used for the Warehousing Interface to (1) check for the*/
/*          : need to continue processing; (2) move the relevant     */
/*          : fields to an appropriate work area; and (3) call       */
/*          : one or more subprograms to continue processing.        */
/*          : This .t program should remain short, relying on        */
/*          : subprograms to perform most of the work.               */
/*********************************************************************/
/*                             MODIFY LOG                            */
/*********************************************************************/
/*Revision 8.5          Last Modified:  03/19/95 BY: BHolmes *J0FY*  */
/*Revision 8.5          Last Modified:  06/25/96 BY: BHolmes *J0M9*  */
/*Revision 8.5          Last Modified:  07/19/96 BY: fwy     *J0MB*  */
/*Revision 8.5          Last Modified:  07/27/96 BY: fwy     *J12B*  */
/*Revision 8.5          Last Modified:  01/07/97 BY: jpm     *J1DM*  */
/*Revision 9.1          Last Modified:  09/07/99 BY: *N02J* Robert Jensen   */
/*Revision 9.1          Last Modified:  08/13/00 BY: *N0KR* myb             */
/*                                                                   */
/*                                                                   */
/*********************************************************************/

TRIGGER PROCEDURE FOR DELETE OF LAD_DET.

/*J12B  if not can-find(first whl_mstr where whl_mstr.whl_act no-lock) */
/*J12B  then leave. */

    {mfdeclre.i }
/*J0MB*/define new shared variable w-site-loc-id like
/*J0MB*/  whl_mstr.whl_src_dest_id.
    define new shared work-table wf_old_lad_det like lad_det.
    define new shared variable w-recid as recid.
/*J0M9*/define new shared variable w-te_type as character.
    define variable w-file as character format "x(24)".


    /* Warehousing Interface processing */

    WI:
    do:

    /* If there is no active external warehouse that is flagged to
    receive sales order, distribution order, work order, or
    repetitive picklist export transactions, then do not process */
/*J12B*/    if not can-find(first whl_mstr no-lock
/*J12B*/        where whl_mstr.whl_act
/*J12B*/          and (whl_mstr.whl_so_exp
/*J12B*/           or  whl_mstr.whl_do_exp
/*J12B*/           or  whl_mstr.whl_wo_exp
/*J12B*/           or  whl_mstr.whl_rps_exp))
/*J12B*/    then leave WI.

    /* If the lad_det record is not associated with a sales order,
    distribution order, work order, or repetitive picklist,
    then do not process */
        if    lad_det.lad_dataset ne "wod_det"
          and lad_det.lad_dataset ne "sod_det"
          and lad_det.lad_dataset ne "ds_det"
          and lad_det.lad_dataset ne "rps_det"
        then leave WI.

    /* If there is no picked quantity on the lad_det,
    then do not process */
/*J0M9*/    if lad_det.lad_qty_pick /*J0MB lt */ le 0
/*J0M9*/    then leave WI.

/*J12B      assign w-recid = recid(lad_det). */

    /* If some quantity has been issued/shipped on the order line,
    then do not process */

    /* Check sales order line */
        if lad_det.lad_dataset = "sod_det"
        then do:
            find first sod_det no-lock
                 where sod_det.sod_nbr = lad_det.lad_nbr
                   and sod_det.sod_line = integer(lad_det.lad_line).
/*J0MB          if not(lad_det.lad_qty_pick > 0 */
/*J0MB             and sod_det.sod_qty_ship = 0) */
/*J0MB*/        if sod_det.sod_qty_ship ne 0
            then leave WI.
        end.

    /* Check work order line */
        if lad_det.lad_dataset = "wod_det"
        then do:
            find first wod_det no-lock
                 where wod_det.wod_lot  = lad_det.lad_nbr
/*J12B*/               and wod_det.wod_op   = integer(lad_det.lad_line)
                   and wod_det.wod_part = lad_det.lad_part.
/*J0MB          if not(lad_det.lad_qty_pick > 0 */
/*J0MB             and wod_det.wod_qty_iss = 0) */
/*J0MB*/        if wod_det.wod_qty_iss ne 0
            then leave WI.
        end.

    /* Check distribution order line */
        if lad_det.lad_dataset = "ds_det"
        then do:
            find first ds_det
                 where ds_det.ds_req_nbr  = lad_det.lad_nbr
                   and ds_det.ds_shipsite = lad_det.lad_site
                   and ds_det.ds_site     = lad_det.lad_line.
/*J12B                 and ds_det.ds_part    = lad_det.lad_part. */
/*J0MB          if not(lad_det.lad_qty_pick > 0 */
/*J0MB             and ds_det.ds_qty_ship = 0) */
/*J0MB*/        if ds_det.ds_qty_ship ne 0
            then leave WI.
        end.

/*J0MB      if lad_det.lad_dataset = "rps_det" */
/*J0MB      then do: */
/*J0MB          if lad_det.lad_qty_pick eq 0 then leave. */
/*J0MB      end. */

    /* Move key lad_det values to work table for subsequent processing */
/*J12B*/    assign w-recid = recid(lad_det).
        create wf_old_lad_det.
        if recid(wf_old_lad_det)= -1 then .
        assign
            wf_old_lad_det.lad_dataset   = lad_det.lad_dataset
        wf_old_lad_det.lad_nbr       = lad_det.lad_nbr
            wf_old_lad_det.lad_line      = lad_det.lad_line
            wf_old_lad_det.lad_site      = lad_det.lad_site
            wf_old_lad_det.lad_loc       = lad_det.lad_loc
            wf_old_lad_det.lad_part      = lad_det.lad_part
/*J0M9*/        wf_old_lad_det.lad_qty_pick  = lad_det.lad_qty_pick.

    /* Call subprogram to create export transactions for warehouse */
        w-file = "wiladd.p".
/*J1DM*/ /* {gprun.i ""wiladd.p""} */
/*J1DM*/    {gprunmo.i &module="WI"
                       &program="wiladd.p"}
/*J12B*/end. /* WI */

/*N02J*//* Logistics Interface processing */
/*N02J*/LG:
/*N02J*/do:
/*N02J*/   if can-find (first lgs_mstr where lgs_app_id > "") then do:
/*N02J*/      if (lad_det.lad_dataset = "sod_det") then do:
/*N02J*/         if not can-find(first wf_old_lad_det) then do:
/*N02J*/            create wf_old_lad_det.
/*N02J*/            if recid(wf_old_lad_det)= -1 then .
/*N02J*/         end.
/*N02J*/         buffer-copy lad_det to wf_old_lad_det no-error.
/*N02J*//*       Call subprogram to publish changed status for Logistics */
/*N02J*/         {gprunmo.i &module="LG"
/*N02J*/         &program="lgladex.p"
/*N02J*/         &param="""(input recid(lad_det), input yes)"""}
/*N02J*/      end. /* sod_det */
           end.
/*N02J*/end. /* LG */
/*N02J*//*End of Added Section */
